﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer;
using DataAccessLayer.DAL;

namespace BestBuy.UserControls
{
    public partial class ProductDetail : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void LoadInfo(int productID)
        {
            ProductCategory pro = ProductCategoryDAL.GetAllSeller(productID);
            SellerListCheckBoxList.DataSource = pro.Users;
            SellerListCheckBoxList.DataBind();
            PaymentCheckBoxList .DataSource = PaymentTypeDAL.GetAllPayment();
            PaymentCheckBoxList.DataBind();
            ProductLable.Text = pro.Name;
            hidProduct.Value = pro.ID.ToString();
        }

        public int ProdictID
        {
            get
            {
                return int.Parse(hidProduct.Value);
            }
        }
        public Dictionary<string, int> SellerList
        {
            get
            {
                Dictionary<string, int> list = new Dictionary<string, int>();
                for (int i = 0; i < SellerListCheckBoxList.Items.Count; i++)
                {
                    if (SellerListCheckBoxList.Items[i].Selected)
                    {
                        list.Add(SellerListCheckBoxList.Items[i].Text,int.Parse(SellerListCheckBoxList.Items[i].Value));
                    }
                }
                return list;
            }
        }
        public bool AllowOthersSellerJoin
        {
            get
            {
                return AllowOthersSellerJoinCheckBox.Checked;
            }
        }
        public string Title
        {
            get
            {
                return TitleTextBox.Text;
            }
        }
        public string SubTitle
        {
            get
            {
                return SubTitleTextBox.Text;
            }
        }
        public string Description
        {
            get
            {
                return DescriptionTextBox.Text;
            }
        }
        public string ImageUrl
        {
            get
            {
                return ImageFileUpload.FileName;
            }
        }
        public int Quantity
        {
            get
            {
                return int.Parse(QuantityTextBox.Text);
            }
        }
        public int StartPrice
        {
            get
            {
                return int.Parse(StartPriceTextBox.Text);
            }
        }
        public int MaxPrice
        {
            get
            {
                return int.Parse(MaxPriceTextBox.Text);
            }
        }
        public bool AuctionType
        {
            get
            {
                return bool.Parse(AuctionTypeRadio.SelectedValue);
            }
        }
        public DateTime StartTime
        {
            get
            {
                DateTime d = DateTime.Now;
                DateTime.TryParse(StartTimeTextBox.Text, out d);
                return d;
            }
        }
        public DateTime EndTime
        {
            get
            {
                DateTime d = DateTime.Now;
                DateTime.TryParse(EndTimeTextBox.Text, out d);
                return d;
            }
        }
        public Dictionary<string,int> Payment
        {
            get
            {
                Dictionary<string, int> list = new Dictionary<string, int>();
                for (int i = 0; i < PaymentCheckBoxList.Items.Count; i++)
                {
                    if (PaymentCheckBoxList.Items[i].Selected)
                    {
                        list.Add(PaymentCheckBoxList.Items[i].Text, int.Parse(PaymentCheckBoxList.Items[i].Value));
                    }
                }

                return list;
            }
        }
        public string FreeShipping
        {
            get
            {
                return FreeShippingTextBox.Text;
            }
        }
    }
}